<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
const isMac = navigator.platform.indexOf('Mac') === 0;
const kBehaviors = window.internals ? ['mac', 'win'] : isMac ? ['mac'] : ['win'];
for (const behavior of kBehaviors) {
  if (window.internals) {
    internals.settings.setEditingBehavior(behavior);
    internals.settings.setSelectTrailingWhitespaceEnabled(behavior !== 'mac');
  }

selection_test(
  '<div contenteditable dir="ltr">|Lorem <div  dir="rtl">ipsum dolor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">^Lorem| <div dir="rtl">ipsum dolor sit</div> amett</div>',
  `${behavior} 5-0 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">L|orem <div  dir="rtl">ipsum dolor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">L^orem| <div dir="rtl">ipsum dolor sit</div> amett</div>',
  `${behavior} 5-1 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lo|rem <div  dir="rtl">ipsum dolor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">Lo^rem| <div dir="rtl">ipsum dolor sit</div> amett</div>',
  `${behavior} 5-2 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lor|em <div  dir="rtl">ipsum dolor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">Lor^em| <div dir="rtl">ipsum dolor sit</div> amett</div>',
  `${behavior} 5-3 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lore|m <div  dir="rtl">ipsum dolor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">Lore^m| <div dir="rtl">ipsum dolor sit</div> amett</div>',
  `${behavior} 5-4 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem| <div  dir="rtl">ipsum dolor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem ^<div dir="rtl">|ipsum dolor sit</div> amett</div>'
      : '<div contenteditable dir="ltr">Lorem ^<div dir="rtl">|ipsum dolor sit</div> amett</div>',
  `${behavior} 5-5 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">|ipsum dolor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <div dir="rtl">^ipsum| dolor sit</div> amett</div>'
      : '<div contenteditable dir="ltr">Lorem <div dir="rtl">^ipsum |dolor sit</div> amett</div>',
  `${behavior} 5-6 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">i|psum dolor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <div dir="rtl">i^psum| dolor sit</div> amett</div>'
      : '<div contenteditable dir="ltr">Lorem <div dir="rtl">i^psum |dolor sit</div> amett</div>',
  `${behavior} 5-7 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ip|sum dolor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <div dir="rtl">ip^sum| dolor sit</div> amett</div>'
      : '<div contenteditable dir="ltr">Lorem <div dir="rtl">ip^sum |dolor sit</div> amett</div>',
  `${behavior} 5-8 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ips|um dolor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <div dir="rtl">ips^um| dolor sit</div> amett</div>'
      : '<div contenteditable dir="ltr">Lorem <div dir="rtl">ips^um |dolor sit</div> amett</div>',
  `${behavior} 5-9 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsu|m dolor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsu^m| dolor sit</div> amett</div>'
      : '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsu^m |dolor sit</div> amett</div>',
  `${behavior} 5-10 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum| dolor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum^ dolor| sit</div> amett</div>'
      : '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum^ |dolor sit</div> amett</div>',
  `${behavior} 5-11 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum |dolor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum ^dolor| sit</div> amett</div>'
      : '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum ^dolor |sit</div> amett</div>',
  `${behavior} 5-12 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum d|olor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum d^olor| sit</div> amett</div>'
      : '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum d^olor |sit</div> amett</div>',
  `${behavior} 5-13 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum do|lor sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum do^lor| sit</div> amett</div>'
      : '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum do^lor |sit</div> amett</div>',
  `${behavior} 5-14 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum dol|or sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dol^or| sit</div> amett</div>'
      : '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dol^or |sit</div> amett</div>',
  `${behavior} 5-15 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum dolo|r sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dolo^r| sit</div> amett</div>'
      : '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dolo^r |sit</div> amett</div>',
  `${behavior} 5-16 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum dolor| sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dolor^ sit|</div> amett</div>'
      : '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dolor^ |sit</div> amett</div>',
  `${behavior} 5-17 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum dolor |sit</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dolor ^sit|</div> amett</div>',
  `${behavior} 5-18 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum dolor s|it</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dolor s^it|</div> amett</div>',
  `${behavior} 5-19 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum dolor si|t</div> amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dolor si^t|</div> amett</div>',
  `${behavior} 5-20 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum dolor sit</div>| amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dolor sit</div> ^amett|</div>',
  `${behavior} 5-21 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum dolor sit</div> |amett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dolor sit</div> ^amett|</div>',
  `${behavior} 5-22 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum dolor sit</div> a|mett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dolor sit</div> a^mett|</div>',
  `${behavior} 5-23 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum dolor sit</div> am|ett</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dolor sit</div> am^ett|</div>',
  `${behavior} 5-24 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum dolor sit</div> ame|tt</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dolor sit</div> ame^tt|</div>',
  `${behavior} 5-25 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum dolor sit</div> amet|t</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dolor sit</div> amet^t|</div>',
  `${behavior} 5-26 ltr forward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="rtl">ipsum dolor sit</div> amett|</div>',
  selection => selection.modify('extend', 'forward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="rtl">ipsum dolor sit</div> amett|</div>',
  `${behavior} 5-27 ltr forward word`);
}
</script>
